package com.wy.business.manage.message.action;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.wy.business.manage.message.service.SessionService;
import com.wy.business.manage.scenery.actions.CampusSceneryAction;
import com.wy.component.email.SendEmailCode;
import com.wy.framework.actions.AbstractBaseAction;

/**
 * 
 * 项目名称：openportal_coding
 * 类名称：SessionAction
 * 类描述：会话action
 * 创建人：黄忠
 * 创建时间：2016-4-20 下午12:07:32
 * 修改人：黄忠
 * 修改时间：2016-4-20 下午12:07:32
 * 版本信息：@version 1.0
 * Copyright (c) 2016万雍科技（上海）有限公司-版权所有  
 * 修改备注：
 * @version
 */
@ParentPackage("json")
@Namespace("/message/session")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
public class SessionAction extends AbstractBaseAction{
	
	/**
	 * serialVersionUID:TODO（用一句话描述这个变量表示什么）
	 * @since Ver 1.1
	 */
	
	private static final long serialVersionUID = -7404461372851598236L;
	private static Log logger = LogFactory.getLog(CampusSceneryAction.class);
	private List<Map> rows;
	
	@Autowired
	private SessionService sessionService;
	
	/**
	 * 
	 * Function Name               sendMsg                                   
	 * @return          		             
	 * @description 发送消息 单聊3人以下 3人或以上 群聊
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-4-20 下午12:02:33           黄忠                     Initial
	 **********************************************************************
	 */
	@Action(value = "send", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) }) 
	public String sendMsg(){
		String userIds = ServletActionContext.getRequest().getParameter("userId");
		String orgCodes = ServletActionContext.getRequest().getParameter("orgCode");
		String msgContent = ServletActionContext.getRequest().getParameter("msgContent");
		try {
			sessionService.sendMsg(userIds, orgCodes, msgContent);
		} catch (Exception e) {
			rspCode="999999";
			rspMsg = e.getMessage();
			e.printStackTrace();
		}
		return SUCCESS;
		
	}
	
	@Action(value = "sendEmailWx", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
			"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) }) 
	public String sendEmailWx(){
		String emailAddress = ServletActionContext.getRequest().getParameter("emailAddress");
		String companyName = ServletActionContext.getRequest().getParameter("companyName");
		try {
			SendEmailCode.sendEmailWX(emailAddress);
		} catch (Exception e) {
			rspCode="999999";
			rspMsg = e.getMessage();
			e.printStackTrace();
		}
		return SUCCESS;
		
	}


	public List<Map> getRows() {
		return rows;
	}


	public void setRows(List<Map> rows) {
		this.rows = rows;
	}

	
	
}
